// 轮播图功能
const slides = document.querySelectorAll('.slide');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');
let currentSlide = 0;

// 自动轮播
function autoSlide() {
    slides[currentSlide].classList.remove('active');
    currentSlide = (currentSlide + 1) % slides.length;
    slides[currentSlide].classList.add('active');
}

// 设置自动轮播间隔
let slideInterval = setInterval(autoSlide, 5000);

// 手动切换轮播图
function showSlide(index) {
    slides[currentSlide].classList.remove('active');
    currentSlide = (index + slides.length) % slides.length;
    slides[currentSlide].classList.add('active');
}

// 上一张
prevBtn.addEventListener('click', () => {
    clearInterval(slideInterval);
    showSlide(currentSlide - 1);
    slideInterval = setInterval(autoSlide, 5000);
});

// 下一张
nextBtn.addEventListener('click', () => {
    clearInterval(slideInterval);
    showSlide(currentSlide + 1);
    slideInterval = setInterval(autoSlide, 5000);
});

// 移动端导航菜单
const burger = document.querySelector('.burger');
const nav = document.querySelector('.nav-links');
const navLinks = document.querySelectorAll('.nav-links li');

burger.addEventListener('click', () => {
    // 切换导航菜单
    nav.classList.toggle('nav-active');
    
    // 汉堡按钮动画
    burger.classList.toggle('toggle');
    
    // 链接动画
    navLinks.forEach((link, index) => {
        if (link.style.animation) {
            link.style.animation = '';
        } else {
            link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s`;
        }
    });
});

// 滚动时导航栏效果
window.addEventListener('scroll', () => {
    const nav = document.querySelector('.navbar');
    if (window.scrollY > 100) {
        nav.style.backgroundColor = 'rgba(255, 255, 255, 0.95)';
        nav.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
    } else {
        nav.style.backgroundColor = '#fff';
        nav.style.boxShadow = '0 2px 5px rgba(0,0,0,0.1)';
    }
});

// 平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
}); 